#include "read.h"

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>    /* inet(3) functions */
#include <string.h>

int main(int argc, char **argv)
{
    int sock, confd;
    struct sockaddr_in ser_name, cli_name;
    socklen_t clien;
    memset(&ser_name, 0, sizeof(ser_name));

    //bzero();
    sock = socket(PF_INET, SOCK_STREAM, 0);
    if (sock < 0) {
        perror("socket");
	exit(EXIT_FAILURE);
    }

    ser_name.sin_family = AF_INET;
    ser_name.sin_port = htons(12345);
    ser_name.sin_addr.s_addr = htonl(INADDR_ANY);
    bind(sock, (struct sockaddr *)(&ser_name), sizeof(ser_name));
    listen(sock,1024);

    while(1) {
        clien = sizeof(cli_name);
        confd = accept(sock, (struct sockaddr *)(&cli_name), &clien);
        read_data(confd);
    }

}
